<?php
namespace app\api\controller\v1;

use think\Db;
class Index extends Base{
	
	
	
	
	public function kindex(){
		//新闻
		$data['news']=Db::name('new_hangye_info')->where('type',0)->field("id,title,s_title,photo,browse,FROM_UNIXTIME(add_time,'%Y-%m-%d') as add_time")->order('update_time desc')->limit(2)->select();
		//行业
		$data['industry']=Db::name('new_hangye_info')->where('type',1)->field('id,title,s_title,photo')->order('update_time desc')->limit(2)->select();
		//案例
		$data['case']=Db::name('case')->field('id,d_title,x_title,img,huxiang,fengge,mianji')->order('update_time desc')->limit(2)->select();
		return toSuccess('获取成功',$data);
	}
	
	
	public function yindex(){
		$data['industry']=Db::name('new_hangye_info')->where('type',1)->field('id,title,s_title,photo')->order('update_time desc')->limit(2)->select();
		$data['team']	 =Db::name('good_team')->where('status',1)->field('id,name,remark,img')->order('sort asc')->select();
		$data['employees']	 =Db::name('good_employees')->where('status',1)->field('id,name,remark,img,review')->order('sort asc')->select();
		return toSuccess('获取成功',$data);
	}
	
	public function get_new_hangye(){
		$type=input('type',0);  //0新闻1行业
		$page=input('page',1);
		$limit=input('limit',10);
		$data=Db::name('new_hangye_info')->where('type',$type)->field("id,title,s_title,photo,browse,FROM_UNIXTIME(add_time,'%Y-%m-%d') as add_time")->order('update_time desc')->page($page,$limit)->select();
		$conut=Db::name('new_hangye_info')->where('type',$type)->count();
		return toSuccess('获取成功',$data,$conut,ceil($conut/$limit));
	}
	
	public function get_new_hangye_info(){
		$type=input('type',0);  //0新闻1行业
		$id=input('id',null);
		if(empty($id)){
			return toError(0,'参数错误');
		}
		$data_info=Db::name('new_hangye_info')->where('type',$type)->field('id,title,s_title,content,photo,browse')->where('id',$id)->find();
		if(empty($data_info)){
			return toError(0,'数据不存在');
		}
		Db::name('new_hangye_info')->where('id',$id)->setInc('browse');
		$data['info']=$data_info;
		$data['s_info']=Db::name('new_hangye_info')->where('type',$type)->where('id < '.$id)->field('title,id')->find();
		$data['x_info']=Db::name('new_hangye_info')->where('type',$type)->where('id > '.$id)->field('title,id')->find();
		
		return toSuccess('获取成功',$data);
	}
	
	
	
	
	
	
	public function get_case_list(){
		$page=input('page',1);
		$limit=input('limit',10);
		$data=Db::name('case')->field('id,d_title,x_title,img,huxiang,fengge,mianji')->order('update_time desc')->page($page,$limit)->select();
		$conut=Db::name('case')->count();
		return toSuccess('获取成功',$data,$conut,ceil($conut/$limit));
	}
	
	
	public function get_case_info(){
		$id=input('id',null);
		if(empty($id)){
			return toError(0,'参数错误');
		}
		$data=Db::name('case')->field('id,d_title,x_title,img,huxiang,fengge,mianji,jiage,imgs')->where('id',$id)->find();
		if(empty($data)){
			return toError(0,'参数错误');
		}
		
		return toSuccess('获取成功',$data);
	}
	
	public function employees_info(){
		$id=input('id',null);
		if(empty($id)){
			return toError(0,'参数错误');
		}
		$data=Db::name('good_employees')->where('id',$id)->find();
		$data['case_list']=Db::name('case')->where('id','in',$data['a_ids'])->field('img,d_title,huxiang')->select();
		return toSuccess('获取成功',$data);
	}
	
}


